class Cart

	attr_reader :items   

	def initialize
		@items = []
	end
  
	def add_product(product, quantity, price, grind, name)
		current_item = @items.find {|item| item.product == product}    
		if current_item
			current_item.increment_quantity(quantity)
		else
      current_item = CartItem.new(product, quantity, price, grind, name)
			@items << current_item
		end
    current_item
	end

	def total_price
		@items.sum { |item| item.price }
	end

  def total_items
    @items.sum { |item| item.quantity }
  end

  def remove_product(product)
    delete_item = @items.find {|item| item.product == product}
    if delete_item
      @items.delete(delete_item)
    end
   
  end

end
